import { reactive, onMounted } from 'vue'
import { format } from 'date-fns'
import { parseTime } from '@/common/common'
import { ResourceInfo } from '@/service/modules/task-manage/types'
import { delResReq, getResTreeReq } from '@/service/modules/task-manage'

export function useResource() {
  const resVariables = reactive({
    list: []
  })
  const getResources = async () => {
    const res = await getResTreeReq()
    if (res.resp_code === 0) {
      resVariables.list = res.data
    }
  }

  const delResource = async (id: number) => {
    const res = await delResReq({ id: id })
    if (res.resp_code === 0) {
      getResources()
    }
  }

  onMounted(() => {
    getResources()
  })

  return { resVariables, getResources, delResource }
}
